define(['jquery', 'bootstrap', 'bxslider', 'select2', 'iscroll', 'datepicker', 'switcher', 'nicescroll', 'timeago'], function () {
    return {
        init: function () {
            this.initTooltip();
            this.initSlider();
            this.initSelect2();
            this.initIScroll();
            this.initDatepicker();
            this.initSwitcher();
            $('[data-toggle="zoom"]').each(function () {
                $(this).wrap('<div class="zoom"></div>');
            });
            jQuery.timeago.settings.strings = {
                prefixAgo: null,
                prefixFromNow: "从现在开始",
                suffixAgo: "",
                suffixFromNow: null,
                seconds: "不到1分钟",
                minute: "大约1分钟",
                minutes: "%d分钟",
                hour: "大约1小时",
                hours: "大约%d小时",
                day: "1天",
                days: "%d天",
                month: "大约1个月",
                months: "%d月",
                year: "大约1年",
                years: "%d年",
                numbers: [],
                wordSeparator: ""
            };
            $("time.timeago").timeago();
        },

        initSwitcher: function () {
            $('.switch').switcher();
        },

        initDatepicker: function () {
            $('.datepicker').datepicker({
                zIndexOffset: 2000,
                format: "yyyy-mm-dd",
                endDate: this.getDate(0)
            });
        },

        initTooltip: function () {
            $('[data-toggle="tooltip"]').tooltip();
        },

        initSlider: function () {
            if ($('.bxslider').closest('.bx-wrapper').length === 0) {
                $('.bxslider').bxSlider({
                    startSlide: 0,
                    minSlides: 7,
                    maxSlides: 7,
                    auto: false,
                    slideMargin: 20,
                    controls: true,
                    pager: false,
                    responsive: false,
                    infiniteLoop: false
                });
            }
            if ($('.news-list').closest('.bx-wrapper').length === 0) {
                $('.news-list').bxSlider({
                    startSlide: 0,
                    minSlides: 1,
                    maxSlides: 4,
                    slideWidth: 260,
                    slideMargin: 10,
                    infiniteLoop: true,
                    pager: false
                });
            }
            if ($('.partner-list').closest('.bx-wrapper').length === 0) {
                $('.partner-list').bxSlider({
                    startSlide: 0,
                    minSlides: 1,
                    maxSlides: 6,
                    slideWidth: 190,
                    slideMargin: 10,
                    infiniteLoop: true,
                    pager: false
                });
            }
        },

        initSelect2: function () {
            $('.select2').select2();
        },


        initIScroll: function () {
            if ($('#SiteMenu').length > 0) {
                var SiteMenu = new IScroll('#SiteMenu', {
                    scrollbars: true,
                    mouseWheel: true
                });
            }
            if ($('#OrderMessage').length > 0) {
                var OrderMessage = new IScroll('#OrderMessage', {
                    scrollbars: true,
                    mouseWheel: true
                });
            }

            //if ($('#AddressSelect').length > 0) {
            //    var AddressSelect = new IScroll('#AddressSelect', {
            //        scrollbars: true,
            //        mouseWheel: true,
            //    });
            //}
            if ($('#TrendTableWrapper').length > 0) {
                $("#TrendTableWrapper").niceScroll({
                    cursorcolor: 'rgba(0,0,0,0.09)',
                    cursorwidth: '5px'

                });
            }
        },
        //# 获取日期
        //
        getDate: function (dayCount) {
            var dd = new Date();
            dd.setDate(dd.getDate() + dayCount);//获取dayCount天后的日期
            var y = dd.getFullYear();
            var m = dd.getMonth() + 1;//获取当前月份的日期
            var d = dd.getDate();
            return y + "-" + m + "-" + d;
        },

    };
});
